/******************************************************************
 *  MRRM's memory access unit                                     *
 *                                                                *
 *  This file is part of the MRRM project                         *
 *  <http://mrrm.googlecode.com/>                                 *
 *                                                                *
 *  Author(s):                                                    *
 *    -  Yuan Pengfei <coolypf@opencores.org>                     *
 *                                                                *
 ******************************************************************
 *                                                                *
 *  Copyright (C) 2010 AUTHORS                                    *
 *                                                                *
 *  This source file may be used and distributed without          *
 *  restriction provided that this copyright statement is not     *
 *  removed from the file and that any derivative work contains   *
 *  the original copyright notice and the associated disclaimer.  *
 *                                                                *
 *  MRRM is free software: you can redistribute it and/or modify  *
 *  it under the terms of the GNU General Public License as       *
 *  published by the Free Software Foundation, either version 3   *
 *  of the License, or (at your option) any later version.        *
 *                                                                *
 *  MRRM is distributed in the hope that it will be useful, but   *
 *  WITHOUT ANY WARRANTY; without even the implied warranty of    *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  *
 *  GNU General Public License for more details.                  *
 *                                                                *
 *  You should have received a copy of the GNU General Public     *
 *  License along with MRRM. If not, see                          *
 *  <http://www.gnu.org/licenses/>.                               *
 *                                                                *
 ******************************************************************/

`include "global.v"

module mrrm_mem(
	// Data memory interface
	dmemaddr, dmemwr, dmemrd, dmemdataw, dmemdatar, dmembyte,
	// MEM interface
	M_itype, M_ifun_b, M_snl, M_valx, M_vale, m_valm
	);

parameter aw = `MEMORY_ADDR_WIDTH;
parameter ow = `OPERAND_WIDTH;

// Interfaces
// Data memory
output [aw-1:0] dmemaddr;
output dmemwr;
output dmemrd;
output [ow-1:0] dmemdataw;
input [ow-1:0] dmemdatar;
output dmembyte;

// MEM
input [2:1] M_itype;
input M_ifun_b;
input M_snl;
input [ow-1:0] M_valx;
input [ow-1:0] M_vale;
output [ow-1:0] m_valm;

// Memory access
assign dmemaddr = M_valx;
assign dmemwr = (M_snl == 1'b0 && M_itype == 2'b01) ? 1'b1 : 1'b0;
assign dmemrd = (M_snl == 1'b1 && M_itype == 2'b01) ? 1'b1 : 1'b0;
assign dmemdataw = M_vale;
assign dmembyte = M_ifun_b;
assign m_valm = dmemdatar;

endmodule
